/*
 * @Author: chululu 83503768@qq.com
 * @Date: 2025-01-24 10:09:36
 * @LastEditors: chululu 83503768@qq.com
 * @LastEditTime: 2025-01-25 10:28:56
 * @FilePath: \tumor-big-screen\src\three\gui.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// gui-setup.js
import * as THREE from 'three';
import { GUI } from "three/addons/libs/lil-gui.module.min.js";

// 创建一个用于控制参数的 GUI
export function setupGUI(object, name = "object") {
  const gui = new GUI();
  // 用于控制模型旋转的开关
  const obectFolder = gui.addFolder(name);
  // 创建用于调试模型的参数对象
  const debugParams = {
    positionx: object.position.x,
    positiony: object.position.y,
    positionz: object.position.z,
    scalex: object.scale.x,
    scaley: object.scale.y,
    scalez: object.scale.z
  };

  // 添加调试项
  obectFolder.add(debugParams, 'positionx', -10, 10).onChange(value => {
    object.position.x = value;
  });
  obectFolder.add(debugParams, 'positiony', -10, 10).onChange(value => {
    object.position.y = value;
  });
  obectFolder.add(debugParams, 'positionz', 0, 20).onChange(value => {
    object.position.z = value;
  });
  obectFolder.add(debugParams, 'scalex', 0, 0.05, 0.001).onChange(value => {
    object.scale.x = value;
  });
  obectFolder.add(debugParams, 'scaley', 0, 0.05, 0.001).onChange(value => {
    object.scale.y = value;
  });
  obectFolder.add(debugParams, 'scalez', 0, 0.05, 0.001).onChange(value => {
    object.scale.z = value;
  });
  // 将调试面板添加到页面
  return gui;
}

export function camerGUi(camera) {

  const gui = new GUI();
  // 设置调节参数
  const cameraSettings = {
    near: camera.near,
    far: camera.far,
  };

  // 添加控制项
  gui.add(cameraSettings, 'near', 0.1, 100).onChange((value) => {
    camera.near = value;
    camera.updateProjectionMatrix(); // 更新相机投影矩阵
  });
  gui.add(cameraSettings, 'far', 100, 10000).onChange((value) => {
    camera.far = value;
    camera.updateProjectionMatrix(); // 更新相机投影矩阵
  });

  return gui;
}